// 声明全局变量gbGoodsAttrIds，用于保存商品属性ID字符串
var gbGoodsAttrIds = [];
// 声明全局变量gbQueryTime，用于保存用户首次查询订单时间
var gbQueryTime = null;

$(function() {
			if (document.addEventListener) {
				document.addEventListener("keypress", eventHandler, false);
			} else {
				document.attachEvent("onkeypress", eventHandler);
			}
		});

/**
 * 页面事件处理器
 * 
 * @param {}
 *            evt
 */
function eventHandler(evt) {
	// 回车监听事件
	if (evt.keyCode == 13) {
		var emailOrUserName = document.getElementById("emailOrUserName");
		var bmbPassword = document.getElementById("bmbPassword");
		var loginBtn = document.getElementById("loginBtn");

		if (typeof(emailOrUserName) == "object"
				&& typeof(bmbPassword) == "object"
				&& typeof(loginBtn) == "object") {
			if (emailOrUserName == document.activeElement
					|| bmbPassword == document.activeElement) {
				loginBtn.focus();
				user_login();
			}
		}
	}
}

/**
 * 前往用户登录页面
 */
function user_toLogin() {
	// 清除指定的cookie
	CookieUtils.deleteCookie("prehrefcookie");

	// 获得跳转前的地址栏
	var href = window.location.href;

	// 设置该地址栏至cookie
	CookieUtils.setCookie("prehrefcookie", href, CookieUtils.expdate, "/", null, false);

	window.location.href = __contextPath + "/user/login.xhtml";
}

/**
 * 用户登录
 */
function user_login(pageText) {
	var $emailOrUserName = $("#emailOrUserName").val();
	var $bmbPassword = $("#bmbPassword").val();
	var msg = "";

	if (Utils.isEmpty($emailOrUserName)) {
		msg += Pmt.warn_emailorusername_blank + "\n";
	}

	if (Utils.isEmpty($bmbPassword)) {
		msg += Pmt.warn_pwd_blank + "\n";
	}

	if (!Utils.isEmpty(msg)) {
		alert(msg);
		return;
	}

	$.ajax({
				url : __contextPath + "/user/login.xhtml",
				type : "POST",
				data : {
					emailOrUserName : $emailOrUserName,
					bmbPassword : $bmbPassword
				},
				cache : false,
				dataType : 'text',
				success : function(data) {
					if (data == "succ") {
						if (pageText == "loginOrRegister") {
							window.location.href = __contextPath
									+ "/order/orderDetail.xhtml";
						} else {
							window.location.href = __contextPath
									+ "/user/loginSucc.xhtml";
						}
					} else {
						window.location.href = __contextPath
								+ "/user/loginFail.xhtml";
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}

/**
 * 返回至登录前的那一页
 */
function user_backToPrePage() {
	// 将跳转的地址，默认跳转到首页
	var jumpHref = __contextPath + "/index.xhtml";
	// 无需执行跳转的特殊地址（登出）
	var specialHref = "logoutSucc.xhtml";
	// 从cookie中读取登录前的地址信息
	var preHref = CookieUtils.getCookie("prehrefcookie");

	if (preHref != null && preHref != "") {
		if (preHref.indexOf(specialHref) <= 0) {
			jumpHref = preHref;
		}

		// 清除指定的cookie
		CookieUtils.deleteCookie("prehrefcookie");
	}

	window.location.href = jumpHref;
}

/**
 * 用户登出
 */
function user_logout() {
	// 清除指定的cookie
	CookieUtils.deleteCookie("prehrefcookie");

	$.ajax({
		url : __contextPath + "/user/logout.xhtml",
		type : "POST",
		cache : false,
		dataType : 'text',
		success : function(data) {
			if (data == "succ") {
				window.location.href = __contextPath + "/user/logoutSucc.xhtml";
			}
		},
		error : function(jqXHR, textStatus, errorThrown) {
			alert(jqXHR.responseText);
		}
	});
}

/**
 * 验证用户名
 * 
 * @param {}
 *            bmbNick
 */
function user_chkNick(bmbNick) {
	var submit_disabled = true;
	var unlen = bmbNick.replace(/[^\x00-\xff]/g, "**").length;
	var $notice = $("#nick_notice");
	var $registerBtn = $("#registerBtn");

	if (Utils.isEmpty(bmbNick)) {
		$notice.html(Pmt.msg_username_blank);
	} else if (!Utils.chkStrCode(bmbNick)) {
		$notice.html(Pmt.msg_username_format);
	} else if (unlen < 3) {
		$notice.html(Pmt.warn_username_shorter);
	} else if (unlen > 14) {
		$notice.html(Pmt.msg_username_length);
	} else {
		submit_disabled = false;
	}

	if (submit_disabled) {
		$registerBtn.attr('disabled', true);
		return;
	}

	$.ajax({
				url : __contextPath + "/user/chkNick.xhtml",
				type : "POST",
				data : {
					bmbNick : bmbNick
				},
				cache : false,
				dataType : 'text',
				success : function(data) {
					if (data == "succ") {
						$notice.html(Pmt.msg_can_reg);
						$registerBtn.attr('disabled', false);
					} else {
						$notice.html(Pmt.msg_username_is_reg);
						$registerBtn.attr('disabled', true);
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}

/**
 * 验证邮箱
 * 
 * @return {Boolean}
 */
function user_chkEmail(bmbEmail) {
	var submit_disabled = true;
	var $notice = $("#email_notice");
	var $registerBtn = $("#registerBtn");

	if (Utils.isEmpty(bmbEmail)) {
		$notice.html(Pmt.msg_email_blank);
	} else if (!Utils.isEmail(bmbEmail)) {
		$notice.html(Pmt.msg_email_format);
	} else {
		submit_disabled = false;
	}

	if (submit_disabled) {
		$registerBtn.attr('disabled', true);
		return;
	}

	$.ajax({
				url : __contextPath + "/user/chkEmail.xhtml",
				type : "POST",
				data : {
					bmbEmail : bmbEmail
				},
				cache : false,
				dataType : 'text',
				success : function(data) {
					if (data == "succ") {
						$notice.html(Pmt.msg_can_reg);
						$registerBtn.attr('disabled', false);
					} else {
						$notice.html(Pmt.msg_email_is_reg);
						$registerBtn.attr('disabled', true);
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}

/**
 * 验证密码
 */
function user_chkPwd(password) {
	var $notice = $("#password_notice");

	if (password.length < 6) {
		$notice.html(Pmt.warn_pwd_shorter);
	} else {
		$notice.html(Pmt.msg_can_reg);
	}
}

/**
 * 验证密码强度级别
 */
function user_chkPwdLevel(password) {
	var O_color = "2px solid #eeeeee";
	var L_color = "2px solid #FF0000";
	var M_color = "2px solid #FF9900";
	var H_color = "2px solid #33CC00";

	if (Utils.isEmpty(password)) {
		Lcolor = Mcolor = Hcolor = O_color;
	} else {
		var S_level = Utils.checkStrong(password);
		switch (S_level) {
			case 0 :
				Lcolor = Mcolor = Hcolor = O_color;
			case 1 :
				Lcolor = L_color;
				Mcolor = Hcolor = O_color;
				break;
			case 2 :
				Lcolor = Mcolor = M_color;
				Hcolor = O_color;
				break;
			default :
				Lcolor = Mcolor = Hcolor = H_color;
		}
	}

	$("#pwd_lower").css({
				"borderBottom" : Lcolor
			});
	$("#pwd_middle").css({
				"borderBottom" : Mcolor
			});
	$("#pwd_high").css({
				"borderBottom" : Hcolor
			});
}

/**
 * 验证确认密码(register.html)
 */
function user_chkCfmPwd(confirmPassword) {
	var password = $("#bmbPassword").val();
	var $notice = $("#cfm_password_notice");

	if (confirmPassword.length < 6) {
		$notice.html(Pmt.warn_cfm_pwd_shorter);
	} else if (confirmPassword != password) {
		$notice.html(Pmt.warn_cfm_pwd_invalid);
	} else {
		$notice.html(Pmt.msg_can_reg);
	}
}

/**
 * 验证确认密码（loginOrRegister.html）
 */
function user_chkCfmPwd_2(confirmPassword) {
	var password = document.registerForm.userPassowrd.value;
	var $notice = $("#cfm_password_notice");

	if (confirmPassword.length < 6) {
		$notice.html(Pmt.warn_cfm_pwd_shorter);
	} else if (confirmPassword != password) {
		$notice.html(Pmt.warn_cfm_pwd_invalid);
	} else {
		$notice.html(Pmt.msg_can_reg);
	}
}

/**
 * 验证手机
 * 
 * @param {}
 *            mobile
 */
function user_chkMobile(mobile) {
	var submit_disabled = true;
	var $notice = $("#mobile_notice");
	var $registerBtn = $("#registerBtn");

	if (Utils.isEmpty(mobile)) {
		$notice.html(Pmt.msg_mobile_blank);
	} else if (!Utils.isMobile(mobile)) {
		$notice.html(Pmt.msg_mobile_format);
	} else {
		submit_disabled = false;
		$notice.html(Pmt.msg_can_reg);
	}

	if (submit_disabled) {
		$registerBtn.attr('disabled', true);
	}
}

/**
 * 验证密保答案输入框
 */
function user_chkAnswer(answer) {
	var submit_disabled = true;
	var $notice = $("#answer_notice");
	var $registerBtn = $("#registerBtn");

	if (Utils.isEmpty(answer)) {
		$notice.html(Pmt.msg_pwd_answer_blank);
	} else {
		submit_disabled = false;
		$notice.html(Pmt.msg_can_reg);
	}

	if (submit_disabled) {
		$registerBtn.attr('disabled', true);
	}
}

/**
 * 发送 邮件地址找回密码邮件
 */
function user_getPwdByEmail() {
	var $bmbNick = $("#bmbNick").val();
	var $bmbEmail = $("#bmbEmail").val();
	var errorMsg = '';

	if (Utils.isEmpty($bmbNick)) {
		errorMsg += Pmt.info_username_blank + '\n';
	}

	if (Utils.isEmpty($bmbEmail)) {
		errorMsg += Pmt.info_email_blank + '\n';
	} else {
		if (!(Utils.isEmail($bmbEmail))) {
			errorMsg += Pmt.err_email_addr + '\n';
		}
	}

	if (!Utils.isEmpty(errorMsg)) {
		alert(errorMsg);
		return;
	}

	$("#mailNotice").show();

	$.ajax({
				url : __contextPath + "/user/getPwdByEmail.xhtml",
				type : "POST",
				data : {
					bmbNick : $bmbNick,
					bmbEmail : $bmbEmail
				},
				cache : false,
				dataType : 'json',
				success : function(data) {
					if (data.status == "succ") {
						window.location.href = __contextPath
								+ "/user/sendPRESucc.xhtml?emailUrl="
								+ data.message;
					} else if (data.status == "fail_1") {
						window.location.href = __contextPath
								+ "/user/getPwdFail_1.xhtml";
					} else if (data.status == "fail_2") {
						window.location.href = __contextPath
								+ "/user/getPwdFail_2.xhtml";
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});

}

/**
 * 重置密码（设置新密码）
 */
function user_setNewPwd() {
	// 检查输入
	var msg = "";
	var $password = $("#bmbPassword").val();
	var $cfmPassword = $("#cfmPassword").val();

	if (Utils.isEmpty($password)) {
		msg += Pmt.warn_new_pwd_blank + '\n';
	} else {
		if ($password.length < 6) {
			msg += Pmt.warn_new_pwd_shorter + '\n';
		}
	}

	if (Utils.isEmpty($cfmPassword)) {
		msg += Pmt.warn_cfm_pwd_blank + '\n';
	}

	if ($cfmPassword != $password) {
		msg += Pmt.warn_cfm_pwd_invalid + '\n';
	}

	if (!Utils.isEmpty(msg)) {
		alert(msg);
		return;
	}

	$.ajax({
				url : __contextPath + "/user/setNewPwd.xhtml",
				type : "POST",
				data : {
					newPwd : $password,
					bmbId : $("#customerId").val()
				},
				cache : false,
				dataType : 'text',
				success : function(data) {
					if (data == "succ") {
						window.location.href = __contextPath
								+ "/user/setNewPwdSucc.xhtml";
					} else {
						window.location.href = __contextPath
								+ "/user/setNewPwdFail.xhtml";
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}

/**
 * 密保问题找回密码 - 1
 */
function user_getPwdByQues() {
	var bmbNick = $("#bmbNick").val();
	var msg = '';

	if (Utils.isEmpty(bmbNick)) {
		msg += Pmt.info_username_blank + '\n';
	}

	if (!Utils.isEmpty(msg)) {
		alert(msg);
		return;
	}

	$.ajax({
				url : __contextPath + "/user/getPwdQues.xhtml",
				type : "POST",
				data : {
					bmbNick : bmbNick
				},
				cache : false,
				dataType : 'json',
				success : function(data) {
					if (data.status == "succ") {
						window.location.href = __contextPath
								+ "/user/getPwdQues.xhtml?bmbId=" + data.bmbId
								+ "&bmbquestion=" + data.bmbquestion;
					} else {
						window.location.href = __contextPath
								+ "/user/getPwdFail_3.xhtml";
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});

}

/**
 * 验证密保答案
 */
function user_validAnswer() {
	var bmbId = $("#bmbId").val();
	var bmbAnswer = $("#bmbAnswer").val();

	$.ajax({
				url : __contextPath + "/user/validAnswer.xhtml",
				type : "POST",
				data : {
					bmbId : bmbId,
					bmbAnswer : bmbAnswer
				},
				cache : false,
				dataType : 'json',
				success : function(data) {
					if (data.status == "succ") {
						window.location.href = __contextPath
								+ "/user/resetPwd_2.xhtml?status="
								+ data.status + "&bmbId=" + data.bmbId;
					} else {
						window.location.href = __contextPath
								+ "/user/getPwdFail_4.xhtml";
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}

/**
 * 检查注册表单
 * 
 * @param {}
 *            pageText 区分不同页面调用此方法
 * @return {Boolean}
 */
function user_chkRegForm(pageText) {
	// 检查输入
	var msg = "";
	var bmbNick = Utils.trim($("#bmbNick").val());
	var email = Utils.trim($("#bmbEmail").val());
	var password = $("#bmbPassword").val();
	var cfmPassword = $("#cfmPassword").val();

	if (Utils.isEmpty(bmbNick)) {
		msg += Pmt.warn_username_blank + '\n';
	} else if (bmbNick.match(/^\s*$|^c:\\con\\con$|[%,\'\*\"\s\t\<\>\&\\]/)) {
		msg += Pmt.warn_username_invalid + '\n';
	}

	if (Utils.isEmpty(email)) {
		msg += Pmt.warn_email_blank + '\n';
	} else if (!(Utils.isEmail(email))) {
		msg += Pmt.warn_email_invalid + '\n';
	}

	if (Utils.isEmpty(password)) {
		msg += Pmt.warn_pwd_blank + '\n';
	} else {
		if (/ /.test(password) == true) {
			msg += Pmt.warn_pwd_has_blank + '\n';
		} else if (password.length < 6) {
			msg += Pmt.warn_pwd_shorter + '\n';
		}
	}

	if (cfmPassword != password) {
		msg += Pmt.warn_cfm_pwd_invalid + '\n';
	}

	if (pageText == "register") {
		if (!$("#agreement").attr("checked"))
			return false;

		var bmbMobile = $("#bmbMobile").val();
		var bmbQuestion = $("#bmbQuestion").val();
		var bmbAnswer = Utils.trim($("#bmbAnswer").val());

		if (Utils.isEmpty(bmbMobile)) {
			msg += Pmt.warn_mobile_blank + '\n';
		}

		if (bmbQuestion == "0") {
			msg += Pmt.warn_unselect_ques + '\n';
		}

		if (Utils.isEmpty(bmbAnswer)) {
			msg += Pmt.warn_pwd_answer_blank + '\n';
		}
	}

	if (!Utils.isEmpty(msg)) {
		alert(msg);
		return false;
	}

	return true;
}

/**
 * 用户注册
 * 
 * @param {}
 *            pageText 区分不同页面调用此方法
 */
function user_register(pageText) {
	if (pageText == "loginOrRegister") {
		if (user_chkRegForm(pageText)) {
			var $bmbNick = $("#bmbNick").val();
			var $bmbEmail = $("#bmbEmail").val();
			var $bmbPassword = $("#bmbPassword").val();

			$.ajax({
						url : __contextPath + "/user/reg.xhtml",
						type : "POST",
						data : {
							bmbNick : $bmbNick,
							bmbEmail : $bmbEmail,
							bmbPassword : $bmbPassword,
							actDir : pageText
						},
						cache : false,
						dataType : 'text',
						success : function(data) {
							if (!Utils.isEmpty(data)) {
								window.location.href = __contextPath
										+ "/user/regSucc.xhtml?emailUrl="
										+ data;
							}
						},
						error : function(jqXHR, textStatus, errorThrown) {
							alert(jqXHR.responseText);
						}
					});
		}
	} else if (pageText == "register") {
		if (user_chkRegForm(pageText)) {
			var $bmbNick = $("#bmbNick").val();
			var $bmbEmail = $("#bmbEmail").val();
			var $bmbMobile = $("#bmbMobile").val();
			var $bmbPassword = $("#bmbPassword").val();
			var $bmbQuestion = $("#bmbQuestion").val();
			var $bmbAnswer = $("#bmbAnswer").val();
			var $bmbSmnotify = $("input:radio[name='bmbSmnotify']:checked")
					.val();
			var $bmbEmnotify = $("input:radio[name='bmbSmnotify']:checked")
					.val();

			// 该数组用于保存所有动态产生的HTML标签的值
			var dynamicDataArray = [];

			if (!Utils.isEmpty(gbDynamicItems)) {
				for (var i = 0; i < gbDynamicItems.length; i++) {
					var tempArray = gbDynamicItems[i].toString().split("==");
					var tempVal = "";

					if (tempArray[1] == 3) { // 单选框
						tempVal = $("input:radio[name='" + tempArray[0]
								+ "']:checked").val();

					} else if (tempArray[1] == 4) { // 复选框
						$("input:checkbox[name='" + tempArray[0] + "']").each(
								function() {
									if ($(this).attr("checked")) {
										tempVal += $(this).val() + "，";
									}
								});

						tempVal = tempVal
								.substring(0, tempVal.lastIndexOf("，"));

					} else { // 普通文本框、文本域、下拉列表框等
						tempVal = $("#" + tempArray[0]).val();
					}

					dynamicDataArray[i] = {
						bmiItem : tempArray[0],
						bmiValue : tempVal
					};
				}
			}

			$.ajax({
						url : __contextPath + "/user/reg.xhtml",
						type : "POST",
						data : {
							bmbNick : $bmbNick,
							bmbEmail : $bmbEmail,
							bmbMobile : $bmbMobile,
							bmbPassword : $bmbPassword,
							bmbQuestion : $bmbQuestion,
							bmbAnswer : $bmbAnswer,
							bmbSmnotify : $bmbSmnotify,
							bmbEmnotify : $bmbEmnotify,
							dataArray : $.toJSON(dynamicDataArray)
						},
						cache : false,
						dataType : 'text',
						success : function(data) {
							if (!Utils.isEmpty(data)) {
								window.location.href = __contextPath
										+ "/user/regSucc.xhtml?emailUrl="
										+ data;
							}
						},
						error : function(jqXHR, textStatus, errorThrown) {
							alert(jqXHR.responseText);
						}
					});

		}
	}

}

/**
 * 用户中心 - 检查用户信息表单
 */
function user_chkUserForm() {
	var email = Utils.trim($("#bmbEmail").val());
	var bmbMobile = $("#bmbMobile").val();
	var bmbQuestion = $("#bmbQuestion").val();
	var bmbAnswer = Utils.trim($("#bmbAnswer").val());

	// 检查输入
	var msg = "";

	if (Utils.isEmpty(email)) {
		msg += Pmt.warn_email_blank + '\n';
	} else if (!(Utils.isEmail(email))) {
		msg += Pmt.warn_email_invalid + '\n';
	}

	if (Utils.isEmpty(bmbMobile)) {
		msg += Pmt.warn_mobile_blank + '\n';
	}

	if (bmbQuestion == "0") {
		msg += Pmt.warn_unselect_ques + '\n';
	}

	if (Utils.isEmpty(bmbAnswer)) {
		msg += Pmt.warn_pwd_answer_blank + '\n';
	}

	if (!Utils.isEmpty(msg)) {
		alert(msg);
		return false;
	}

	return true;
}

/**
 * 用户中心 -编辑用户信息
 */
function user_editUserInfo() {
	if (user_chkUserForm()) {
		var $bmbEmail = $("#bmbEmail").val();
		var $bmbMobile = $("#bmbMobile").val();
		var $bmbQuestion = $("#bmbQuestion").val();
		var $bmbAnswer = $("#bmbAnswer").val();
		var $bmbSmnotify = $("input:radio[name='bmbSmnotify']:checked").val();
		var $bmbEmnotify = $("input:radio[name='bmbSmnotify']:checked").val();

		// 该数组用于保存所有动态产生的HTML标签的值
		var dynamicAllDatas = [];

		if (!Utils.isEmpty(gbAllDynamicItems)) {
			for (var i = 0; i < gbAllDynamicItems.length; i++) {
				var tempArray = gbAllDynamicItems[i].toString().split("==");
				var tempVal = "";

				if (tempArray[1] == 3) { // 单选框
					tempVal = $("input:radio[name='" + tempArray[0]
							+ "']:checked").val();

				} else if (tempArray[1] == 4) { // 复选框
					$("input:checkbox[name='" + tempArray[0] + "']").each(
							function() {
								if ($(this).attr("checked")) {
									tempVal += $(this).val() + "，";
								}
							});

					tempVal = tempVal.substring(0, tempVal.lastIndexOf("，"));

				} else { // 普通文本框、文本域、下拉列表框等
					tempVal = $("#" + tempArray[0]).val();
				}

				dynamicAllDatas[i] = {
					bmiItem : tempArray[0],
					bmiValue : tempVal
				};
			}

			$.ajax({
						url : __contextPath + "/user/editUserInfo.xhtml",
						type : "POST",
						data : {
							bmbEmail : $bmbEmail,
							bmbMobile : $bmbMobile,
							bmbQuestion : $bmbQuestion,
							bmbAnswer : $bmbAnswer,
							bmbSmnotify : $bmbSmnotify,
							bmbEmnotify : $bmbEmnotify,
							dataArray : $.toJSON(dynamicAllDatas)
						},
						cache : false,
						dataType : 'text',
						success : function(data) {
							if (data == "succ") {
								window.location.href = __contextPath
										+ "/user/editUserInfoSucc.xhtml";
							}
						},
						error : function(jqXHR, textStatus, errorThrown) {
							alert(jqXHR.responseText);
						}
					});
		}

	}
}

/**
 * 用户中心 - 检查用户密码信息表单
 */
function user_chkUserPwdForm() {
	var oldPwd = $("#oldPwd").val();
	var newPwd = $("#newPwd").val();
	var cfmPwd = $("#cfmPwd").val();

	// 检查输入
	var msg = "";

	if (Utils.isEmpty(oldPwd)) {
		msg += Pmt.warn_old_Pwd_blank + '\n';
	}

	if (Utils.isEmpty(newPwd)) {
		msg += Pmt.warn_new_pwd_blank + '\n';
	} else {
		if (/ /.test(newPwd) == true) {
			msg += Pmt.warn_pwd_has_blank + '\n';
		} else if (newPwd.length < 6) {
			msg += Pmt.warn_new_pwd_shorter + '\n';
		}
	}

	if (cfmPwd != newPwd) {
		msg += Pmt.warn_cfm_pwd_invalid + '\n';
	}

	if (!Utils.isEmpty(msg)) {
		alert(msg);
		return false;
	}

	return true;
}

/**
 * 用户中心 -修改用户密码
 */
function user_editUserPwd() {
	if (user_chkUserPwdForm()) {
		var oldPwd = $("#oldPwd").val();
		var newPwd = $("#newPwd").val();

		$.ajax({
					url : __contextPath + "/user/editUserPwd.xhtml",
					type : "POST",
					data : {
						oldPwd : oldPwd,
						newPwd : newPwd
					},
					cache : false,
					dataType : 'text',
					success : function(data) {
						if (data == "succ") {
							window.location.href = __contextPath
									+ "/user/editUserPwdSucc.xhtml";
						} else {
							window.location.href = __contextPath
									+ "/user/editUserPwdFail.xhtml";
						}
					},
					error : function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.responseText);
					}
				});
	}

}

/**
 * 用户中心 - 删除收藏夹中指定的商品
 * 
 * @param {}
 *            goodsId
 */
function user_removeFromFav(goodsId) {
	if (confirm(Pmt.cfm_del_fav_goods)) {
		$.ajax({
					url : __contextPath + "/user/removeFromFav.xhtml",
					type : "POST",
					data : {
						goodsId : goodsId
					},
					cache : false,
					dataType : 'text',
					success : function(data) {
						if (data == "succ") {
							window.location.href = __contextPath
									+ "/user/userFav.xhtml";
						} else {
							window.location.href = __contextPath
									+ "/index.xhtml";
						}
					},
					error : function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.responseText);
					}
				});
	}
}

/**
 * 用户中心 - 保存会员收货地址
 * 
 * @return {Boolean}
 */
function user_saveUserAddr() {
	// 获取隐藏域中的收货地址id
	$braId = $("#braId").val();
	$braConsignee = $("#braConsignee").val();
	$braCountry = $("#braCountry").val();
	$braProvince = $("#braProvince").val();
	$braCity = $("#braCity").val();
	$braDistrict = $("#braDistrict").val();
	$braDetail = $("#braDetail").val();
	$braZipcode = $("#braZipcode").val();
	$braMobile = $("#braMobile").val();
	$braPhone = $("#braPhone").val();
	$braTime = $("#braTime").val();
	$braIsdefault = $("input:checkbox[id='braIsdefault']:checked").val();

	// 检查输入
	var msg = "";

	if (Utils.isEmpty($braConsignee)) {
		msg += Pmt.warn_consignee_blank + '\n';
	}

	if ($braCountry == "-1" || $braProvince == "-1" || $braCity == "-1"
			|| $braDistrict == "-1") {
		msg += Pmt.warn_unselect_region + '\n';
	}

	if (Utils.isEmpty($braDetail)) {
		msg += Pmt.warn_addr_detail_blank + '\n';
	}

	if (Utils.isEmpty($braMobile)) {
		msg += Pmt.warn_mobile_blank + '\n';
	} else if (!Utils.isMobile($braMobile)) {
		msg += Pmt.warn_mobile_invalid + '\n';
	}

	if (!Utils.isEmpty(msg)) {
		alert(msg);
		return false;
	}

	$.ajax({
				url : __contextPath + "/user/saveUserAddr.xhtml",
				type : "POST",
				data : {
					braId : $braId,
					braConsignee : $braConsignee,
					braCountry : $braCountry,
					braProvince : $braProvince,
					braCity : $braCity,
					braDistrict : $braDistrict,
					braDetail : $braDetail,
					braZipcode : $braZipcode,
					braMobile : $braMobile,
					braPhone : $braPhone,
					braTime : $braTime,
					braIsdefault : $braIsdefault
				},
				cache : false,
				dataType : 'text',
				success : function(data) {
					if (data == "succ") {
						window.location.href = __contextPath
								+ "/user/userAddr.xhtml";
					} else {
						window.location.href = __contextPath + "/index.xhtml";
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}

/**
 * 用户中心 - 修改默认收货地址
 * 
 * @param {}
 *            addrId
 */
function user_updateUserDefAddr(addrId) {
	$.ajax({
				url : __contextPath + "/user/updateUserDefAddr.xhtml",
				type : "POST",
				data : {
					addrId : addrId
				},
				cache : false,
				dataType : 'text',
				success : function(data) {
					if (data == "succ") {
						window.location.href = __contextPath
								+ "/user/userAddr.xhtml";
					} else {
						window.location.href = __contextPath + "/index.xhtml";
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}

/**
 * 用户中心 - 删除收货地址
 * 
 * @param {}
 *            addrId
 */
function user_deleteUserAddr(addrId) {
	if (confirm(Pmt.cfm_del_useraddr)) {
		$.ajax({
					url : __contextPath + "/user/deleteUserAddr.xhtml",
					type : "POST",
					data : {
						addrId : addrId
					},
					cache : false,
					dataType : 'text',
					success : function(data) {
						if (data == "succ") {
							window.location.href = __contextPath
									+ "/user/userAddr.xhtml";
						} else {
							window.location.href = __contextPath
									+ "/index.xhtml";
						}
					},
					error : function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.responseText);
					}
				});
	}
}

/**
 * 加载国家信息
 * 
 * @param {}
 *            data
 */
function loadCountryData(data, bdrId) {
	// 删除非默认项
	$("#braCountry option[value != '-1']").remove();
	var $braCountry = $("#braCountry");

	if (data != null && data != '[]') {
		for (var i = 0; i < data.length; i++) {
			item = $("<option value='" + data[i].bdrId + "'>" + data[i].bdrName
					+ "</option>");
			$braCountry.append(item);
		}

		if (bdrId != null) {
			// 选择默认
			$("#braCountry option[value=" + bdrId + "]").attr("selected", true);
		}
	}
}

/**
 * 加载省份信息
 * 
 * @param {}
 *            data
 */
function loadProvinceData(data, bdrId) {
	// 删除非默认项
	$("#braProvince option[value != '-1']").remove();
	var $braProvince = $("#braProvince");

	if (data != null && data != '[]') {
		for (var i = 0; i < data.length; i++) {
			item = $("<option value='" + data[i].bdrId + "'>" + data[i].bdrName
					+ "</option>");
			$braProvince.append(item);
		}

		if (bdrId != null) {
			// 选择默认
			$("#braProvince option[value=" + bdrId + "]")
					.attr("selected", true);
		}
	}
}

/**
 * 加载城市信息
 * 
 * @param {}
 *            data
 */
function loadCityData(data, bdrId) {
	// 删除非默认项
	$("#braCity option[value != '-1']").remove();
	var $braCity = $("#braCity");

	if (data != null && data != '[]') {
		for (var i = 0; i < data.length; i++) {
			item = $("<option value='" + data[i].bdrId + "'>" + data[i].bdrName
					+ "</option>");
			$braCity.append(item);
		}

		if (bdrId != null) {
			// 选择默认
			$("#braCity option[value=" + bdrId + "]").attr("selected", true);
		}
	}
}

/**
 * 加载区域信息
 * 
 * @param {}
 *            data
 */
function loadDistrictData(data, bdrId) {
	// 删除非默认项
	$("#braDistrict option[value != '-1']").remove();
	var $braDistrict = $("#braDistrict");

	if (data != null && data != '[]') {
		for (var i = 0; i < data.length; i++) {
			item = $("<option value='" + data[i].bdrId + "'>" + data[i].bdrName
					+ "</option>");
			$braDistrict.append(item);
		}

		if (bdrId != null) {
			// 选择默认
			$("#braDistrict option[value=" + bdrId + "]")
					.attr("selected", true);
		}
	}
}

/**
 * 选择区域事件
 * 
 * @param {}
 *            bdrParent
 * @param {}
 *            level
 */
function selectRegion(bdrParent, level) {
	$.ajax({
				url : __contextPath + "/user/getRegionList.xhtml",
				type : "POST",
				data : {
					bdrParent : bdrParent
				},
				cache : false,
				dataType : 'json',
				success : function(data) {
					if (level == 1) {
						loadProvinceData(data, null);
						loadCityData(null, null);
						loadDistrictData(null, null);
					} else if (level == 2) {
						loadCityData(data, null);
						loadDistrictData(null, null);
					} else if (level == 3) {
						loadDistrictData(data, null);
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			})
}

/**
 * 加载指定所在区域
 * 
 * @param {}
 *            bdrId
 * @param {}
 *            bdrParent
 * @param {}
 *            level
 */
function loadRegionName(bdrId, bdrParent, level) {
	$.ajax({
				url : __contextPath + "/user/getRegionList.xhtml",
				type : "POST",
				data : {
					bdrParent : bdrParent
				},
				cache : false,
				dataType : 'json',
				success : function(data) {
					if (level == 1) {
						loadCountryData(data, bdrId);
					} else if (level == 2) {
						loadProvinceData(data, bdrId);
					} else if (level == 3) {
						loadCityData(data, bdrId);
					} else if (level == 4) {
						loadDistrictData(data, bdrId);
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			})
}

/**
 * 用户中心 - 修改用户地址
 * 
 * @param {}
 *            addrId
 */
function user_updateUserAddr(addrId) {
	$.ajax({
				url : __contextPath + "/user/getUserAddr.xhtml",
				type : "POST",
				data : {
					addrId : addrId
				},
				cache : false,
				dataType : 'json',
				success : function(data) {
					if (data.status == "succ") {
						if (data.braJson != "") {
							$("#userAddrTitle").html("编辑收货人信息");

							// 将收货地址id设置到隐藏域中
							$("#braId").val(data.braJson.braId);
							$("#braConsignee").val(data.braJson.braConsignee);
							$("#braDetail").val(data.braJson.braDetail);
							$("#braZipcode").val(data.braJson.braZipcode);
							$("#braMobile").val(data.braJson.braMobile);
							$("#braPhone").val(data.braJson.braPhone);
							$("#braTime").val(data.braJson.braTime);

							var country = data.braJson.braCountry;
							var province = data.braJson.braProvince;
							var city = data.braJson.braCity;
							var district = data.braJson.braDistrict;

							loadRegionName(country, "0", 1);
							loadRegionName(province, country, 2);
							loadRegionName(city, province, 3);
							loadRegionName(district, city, 4);

							if (parseInt(data.braJson.braIsdefault) == 1) {
								$("input:checkbox[id='braIsdefault']").attr(
										"checked", true);
							} else {
								$("input:checkbox[id='braIsdefault']").attr(
										"checked", false);
							}

							$("#saveUserAddrBtn").attr('disabled', false);
						}
					} else {
						window.location.href = __contextPath + "/index.xhtml";
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}

/**
 * 用户中心 - 删除用户评论
 * 
 * @param {}
 *            bucId
 */
function user_delUserCmt(bucId) {
	if (confirm(Pmt.cfm_del_cmt)) {
		$.ajax({
					url : __contextPath + "/user/removeFromUserCmts.xhtml",
					type : "POST",
					data : {
						bucId : bucId
					},
					cache : false,
					dataType : 'text',
					success : function(data) {
						if (data == "succ") {
							window.location.href = __contextPath
									+ "/user/userCmts.xhtml";
						} else {
							window.location.href = __contextPath
									+ "/index.xhtml";
						}
					},
					error : function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.responseText);
					}
				});
	}
}

/**
 * 会员中心 - 保存用户留言
 */
function user_saveUserMsg() {
	var $bumTitle = $("#bumTitle").val();
	var $bumContent = $("#bumContent").val();
	// 检查输入
	var msg = "";

	if (Utils.isEmpty($bumTitle)) {
		msg += Pmt.warn_msg_title_blank + '\n';
	} else if ($bumTitle.length > 20) {
		msg += Pmt.warn_msg_title_length + '\n';
	}

	if (Utils.isEmpty($bumContent)) {
		msg += Pmt.warn_msg_content_blank + '\n';
	} else if ($bumContent.length > 200) {
		msg += Pmt.warn_msg_content_length + '\n';
	}

	if (!Utils.isEmpty(msg)) {
		alert(msg);
		return;
	}

	// 提交表单
	$("#userMsgForm").attr("action", __contextPath + "/user/saveUserMsg.xhtml")
			.submit();
}

/**
 * 用户中心 - 删除用户留言
 * 
 * @param {}
 *            bucId
 */
function user_delUserMsg(bumId) {
	if (confirm(Pmt.cfm_del_msg)) {
		$.ajax({
					url : __contextPath + "/user/delUserMsg.xhtml",
					type : "POST",
					data : {
						bumId : bumId
					},
					cache : false,
					dataType : 'text',
					success : function(data) {
						if (data == "succ") {
							window.location.href = __contextPath
									+ "/user/userMsg.xhtml";
						} else {
							window.location.href = __contextPath
									+ "/index.xhtml";
						}
					},
					error : function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.responseText);
					}
				});
	}
}

/**
 * 会员中心 - 添加商品值购物车
 * 
 * @param {}
 *            goodsId
 */
function user_addToCart(goodsId) {
	$.ajax({
				url : __contextPath + "/user/getGoodsAttrList.xhtml",
				type : "POST",
				data : {
					goodsId : goodsId
				},
				cache : false,
				dataType : 'json',
				success : function(data) {
					// 验证商品是否存在可选属性或属性列表是否为空
					checkGoodsAttr(goodsId, data);
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}

/**
 * 验证商品是否存在可选属性或属性列表是否为空
 * 
 * @param {}
 *            goodsId
 * @param {}
 *            data
 */
function checkGoodsAttr(goodsId, data) {
	if (data == null || data == '[]') {
		// 直接提交商品至结算中心
		submit_opened_div(goodsId, false);
	} else {
		// 区分是否存在商品可选属性
		var hasAttr = false;

		for (var i = 0; i < data.length; i++) {
			// radio、checkbox
			if (data[i].btaAtype == 1 || data[i].btaAtype == 2) {
				hasAttr = true;
				break;
			}
		}

		if (!hasAttr) {
			// 直接提交商品至结算中心
			submit_opened_div(goodsId, false);
		} else {
			// 打开商品属性层
			openAttrsDiv(goodsId, data);
		}

	}
}

/**
 * 检测图层是否已经存在，存在返回元素，不存在返回false
 * 
 * @param {}
 *            elementId
 * @return {}
 */
function isExistsDiv(elementId) {
	return document.getElementById(elementId) || false;
}

/**
 * 关闭新图层和mask图层
 */
function cancel_opened_div() {
	var open_div = isExistsDiv("openDivId");
	var mask_div = isExistsDiv("maskDivId");

	if (open_div)
		document.body.removeChild(open_div);
	if (mask_div)
		document.body.removeChild(mask_div);
}

/**
 * 创建商品属性层
 * 
 * @param {}
 *            goodsId
 * @param {}
 *            data
 */
function openAttrsDiv(goodsId, data) {
	var open_div_id = "openDivId";
	var mask_div_id = "maskDivId";

	// 检测并关闭旧图层
	cancel_opened_div();

	// 计算上卷元素值
	var scrollPos;
	if (typeof(window.pageYOffset) != 'undefined') {
		scrollPos = window.pageYOffset;
	} else if (typeof(document.compatMode) != 'undefined'
			&& document.compatMode != 'BackCompat') {
		scrollPos = document.documentElement.scrollTop;
	} else if (typeof(document.body) != 'undefined') {
		scrollPos = document.body.scrollTop;
	}

	// 新激活图层
	var newDiv = document.createElement("div");
	newDiv.id = open_div_id;
	newDiv.style.position = "absolute";
	newDiv.style.zIndex = "10000";
	newDiv.style.width = "300px";
	newDiv.style.height = "260px";
	newDiv.style.top = (parseInt(scrollPos + 200)) + "px";
	newDiv.style.left = (parseInt(document.body.offsetWidth) - 200) / 2 + "px"; // 屏幕居中
	newDiv.style.overflow = "auto";
	newDiv.style.background = "#FFF";
	newDiv.style.border = "3px solid #59B0FF";
	newDiv.style.padding = "5px";

	// 生成层内内容
	newDiv.innerHTML = '<h4 style="font-size:14; margin:15 0 0 15;">请选择商品属性</h4>';
	// 区分是否为同一个属性
	var bgaTattri = "";

	for (var i = 0; i < data.length; i++) {
		var btaAtype = data[i].btaAtype;

		if (data[i].bgaTattri != bgaTattri) {
			if (btaAtype == 0) {
				continue;

			} else if (btaAtype == 1) {
				newDiv.innerHTML += '<hr style="color: #EBEBED; height:1px;"><h6 style="text-align:left; background:#ffffff; margin-left:15px;">'
						+ data[i].btaName + '</h6>';

				if (data[i].bgaPrice > 0) {
					newDiv.innerHTML += '<input type="radio" id="'
							+ data[i].bgaId
							+ '" name="rg-'
							+ data[i].bgaTattri
							+ '" value="'
							+ data[i].bgaPrice
							+ '" style="margin-left:15px;" checked="checked" onclick="initGoodsAttrId()"/><font color="#555555">'
							+ data[i].bgaValue + '</font><font>[￥'
							+ data[i].bgaPrice + '元]</font><br />';
				} else {
					newDiv.innerHTML += '<input type="radio" id="'
							+ data[i].bgaId
							+ '" name="rg-'
							+ data[i].bgaTattri
							+ '" value="'
							+ data[i].bgaPrice
							+ '" style="margin-left:15px;" checked="checked" onclick="initGoodsAttrId()"/><font color="#555555">'
							+ data[i].bgaValue + '</font><br />';
				}

			} else if (btaAtype == 2) {
				newDiv.innerHTML += '<hr style="color: #EBEBED; height:1px;"><h6 style="text-align:left; background:#ffffff; margin-left:15px;">'
						+ data[i].btaName + '</h6>';

				if (data[i].bgaPrice > 0) {
					newDiv.innerHTML += '<input type="checkbox" id="'
							+ data[i].bgaId
							+ '" name="cb-'
							+ data[i].bgaTattri
							+ '" value="'
							+ data[i].bgaPrice
							+ '" style="margin-left:15px;" onclick="initGoodsAttrId()"/><font color="#555555">'
							+ data[i].bgaValue + '</font><font>[￥'
							+ data[i].bgaPrice + '元]</font><br />';
				} else {
					newDiv.innerHTML += '<input type="checkbox" id="'
							+ data[i].bgaId
							+ '" name="cb-'
							+ data[i].bgaTattri
							+ '" value="'
							+ data[i].bgaPrice
							+ '" style="margin-left:15px;" onclick="initGoodsAttrId()"/><font color="#555555">'
							+ data[i].bgaValue + '</font><br />';
				}

			}
		} else {
			if (btaAtype == 0) {
				continue;

			} else if (btaAtype == 1) {
				if (data[i].bgaPrice > 0) {
					newDiv.innerHTML += '<input type="radio" id="'
							+ data[i].bgaId
							+ '" name="rg-'
							+ data[i].bgaTattri
							+ '" value="'
							+ data[i].bgaPrice
							+ '" style="margin-left:15px;" onclick="initGoodsAttrId()"/><font color="#555555">'
							+ data[i].bgaValue + '</font><font>[￥'
							+ data[i].bgaPrice + '元]</font><br />';
				} else {
					newDiv.innerHTML += '<input type="radio" id="'
							+ data[i].bgaId
							+ '" name="rg-'
							+ data[i].bgaTattri
							+ '" value="'
							+ data[i].bgaPrice
							+ '" style="margin-left:15px;" onclick="initGoodsAttrId()"/><font color="#555555">'
							+ data[i].bgaValue + '</font><br />';
				}

			} else if (btaAtype == 2) {
				if (data[i].bgaPrice > 0) {
					newDiv.innerHTML += '<input type="checkbox" id="'
							+ data[i].bgaId
							+ '" name="cb-'
							+ data[i].bgaTattri
							+ '" value="'
							+ data[i].bgaPrice
							+ '" style="margin-left:15px;" onclick="initGoodsAttrId()"/><font color="#555555">'
							+ data[i].bgaValue + '</font><font>[￥'
							+ data[i].bgaPrice + '元]</font><br />';
				} else {
					newDiv.innerHTML += '<input type="checkbox" id="'
							+ data[i].bgaId
							+ '" name="cb-'
							+ data[i].bgaTattri
							+ '" value="'
							+ data[i].bgaPrice
							+ '" style="margin-left:15px;" onclick="initGoodsAttrId()"/><font color="#555555">'
							+ data[i].bgaValue + '</font><br />';
				}

			}
		}

		if (btaAtype != 0) {
			bgaTattri = data[i].bgaTattri;
		}
	}

	newDiv.innerHTML += '<br/><center>[<a href="javascript: submit_opened_div(\''
			+ goodsId
			+ '\', true);" class="f6">购买</a>]&nbsp;&nbsp;[<a href="javascript: cancel_opened_div();" class="f6">取消</a>]</center>';

	document.body.appendChild(newDiv);

	// mask图层
	var newMask = document.createElement("div");
	newMask.id = mask_div_id;
	newMask.style.position = "absolute";
	newMask.style.zIndex = "9999";
	newMask.style.width = document.body.scrollWidth + "px";
	newMask.style.height = document.body.scrollHeight + "px";
	newMask.style.top = "0px";
	newMask.style.left = "0px";
	newMask.style.background = "#FFF";
	newMask.style.filter = "alpha(opacity=30)";
	newMask.style.opacity = "0.40";
	document.body.appendChild(newMask);

	// 初始化已选择的商品属性
	initGoodsAttrId();
}

/**
 * 加载选择的商品属性
 */
function initGoodsAttrId() {
	// 清空数组
	gbGoodsAttrIds.length = 0;

	$("#openDivId input:checked").each(function() {
				gbGoodsAttrIds.push(this.id);
			});
}

/**
 * 提交商品及选择的属性列表
 * 
 * @param {}
 *            goodsId
 * @param {}
 *            hasAttr 区分商品是否有属性列表或属性列表是否存在可选项
 */
function submit_opened_div(goodsId, hasAttr) {
	$.ajax({
				url : __contextPath + "/addToCart.xhtml",
				type : "POST",
				data : {
					id : goodsId,
					attr : (hasAttr == true) ? (gbGoodsAttrIds.toString()) : "",
					num : 1
				},
				cache : false,
				dataType : 'text',
				success : function(data) {
					// 关闭新图层和mask图层
					if (hasAttr)
						cancel_opened_div();

					// 跳转至商品结算页面
					window.location.href = __contextPath
							+ "/order/cartorder.xhtml";
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}

/**
 * 用户中心- 取消订单
 * 
 * @param {}
 *            orderId
 */
function user_cancelOrder(orderId) {
	// TODO 前端取消订单，待调整，先完善后台管理！
	
	if (confirm(Pmt.cfm_cancel_order)) {
		$.ajax({
					url : __contextPath + "/user/cancelOrder.xhtml",
					type : "POST",
					data : {
						orderId : orderId
					},
					cache : false,
					dataType : 'text',
					success : function(data) {
						if (data == "succ") {
							window.location.href = __contextPath
									+ "/user/order.xhtml";
						} else {
							window.location.href = __contextPath
									+ "/index.xhtml";
						}
					},
					error : function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.responseText);
					}
				});
	}
}

/**
 * 用户中心 - 合并订单
 */
function user_mergeOrder() {
	// TODO 前端合并订单，待调整，先完善后台管理！
	
	var $mainOrder = $("#mainOrder").val();
	var $fellowOrder = $("#fellowOrder").val();
	var $mergeOrderBtn = $("#mergeOrderBtn");

	if ($mainOrder == "0") {
		alert(Pmt.info_mainorder_seld);
		return;
	} else if ($fellowOrder == "0") {
		alert(Pmt.info_felloworder_seld);
		return;
	} else if ($mainOrder == $fellowOrder) {
		alert(Pmt.info_mainorder_aldseld);
		return;
	}

	if (confirm(Pmt.cfm_merge_order)) {
		$.ajax({
					url : __contextPath + "/user/mergeOrder.xhtml",
					type : "POST",
					data : {
						mainOrder : $mainOrder,
						fellowOrder : $fellowOrder
					},
					cache : false,
					dataType : 'text',
					success : function(data) {
						if (data == "succ") {
							window.location.href = __contextPath
									+ "/user/order.xhtml";
						} else if (data == "unMergedOrder") {
							alert(Pmt.err_unmerged_order);
						} else if (data == "fail") {
							alert(Pmt.err_order_merge_fail);
						} else if (data == "dataError") {
							alert(Pmt.err_order_data_lost);
						} else if (data == "sessionInvalid") {
							window.location.href = __contextPath
									+ "/index.xhtml";
						}
					},
					error : function(jqXHR, textStatus, errorThrown) {
						alert(jqXHR.responseText);
					}
				});
	}
}

/**
 * 用户中心 - 查看订单详情
 * 
 * @param {}
 *            orderId
 */
function user_orderDetail(orderId) {
	window.location.href = __contextPath + "/user/orderDetail.xhtml?orderId="
			+ orderId;
}

/**
 * 用户中心 - 更改订单详情中的收货人信息
 */
function user_updateConsignee() {
	$boiId = $("#boiId").val();
	$boiConsignee = $("#boiConsignee").val();
	$boiZipcode = $("#boiZipcode").val();
	$boiDetail = $("#boiDetail").val();
	$boiPhone = $("#boiPhone").val();
	$boiMobile = $("#boiMobile").val();
	$boiBest = $("#boiBest").val();

	// 检查输入
	var msg = "";

	if (Utils.isEmpty($boiConsignee)) {
		msg += Pmt.warn_consignee_blank + '\n';
	}

	if (Utils.isEmpty($boiDetail)) {
		msg += Pmt.warn_addr_detail_blank + '\n';
	}

	if (Utils.isEmpty($boiMobile)) {
		msg += Pmt.warn_mobile_blank + '\n';
	} else if (!Utils.isMobile($boiMobile)) {
		msg += Pmt.warn_mobile_invalid + '\n';
	}

	if (!Utils.isEmpty(msg)) {
		alert(msg);
		return;
	}

	$.ajax({
				url : __contextPath + "/user/updateConsignee.xhtml",
				type : "POST",
				data : {
					boiId : $boiId,
					boiConsignee : $boiConsignee,
					boiZipcode : $boiZipcode,
					boiDetail : $boiDetail,
					boiPhone : $boiPhone,
					boiMobile : $boiMobile,
					boiBest : $boiBest
				},
				cache : false,
				dataType : 'json',
				success : function(data) {
					if (data.status == "succ") {
						window.location.href = __contextPath
								+ "/user/orderDetail.xhtml?orderId="
								+ data.orderId;
					} else {
						window.location.href = __contextPath + "/index.xhtml";
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}

/**
 * 前端首页 - 查询订单
 */
function orderQuery() {
	var $boiOsn = $("#boiOsnInput").val();

	if ($boiOsn == "") {
		alert(Pmt.info_qorder_blank);
		return;
	}

	var queryTime = new Date();

	if (gbQueryTime == null) {
		gbQueryTime = queryTime;
	} else {
		var seconds = Utils.compareTwoDate(queryTime, gbQueryTime);
		gbQueryTime = queryTime;

		if (seconds <= 3) {
			alert(Pmt.info_operate_continually);
			return;
		}
	}

	$.ajax({
				url : __contextPath + "/user/orderQuery.xhtml",
				type : "POST",
				data : {
					boiOsn : $boiOsn
				},
				cache : false,
				dataType : 'json',
				success : function(data) {
					if (data != null && data != "" && data != "null") {
						$("#ECS_ORDER_QUERY").show();

						var boiOrder_html = "";
						var boiPay_html = "";
						var boiShip_html = "";

						if (data.boiOrder == 0) {
							boiOrder_html = "未确认";
						} else if (data.boiOrder == 1) {
							boiOrder_html = "已确认";
						} else if (data.boiOrder == 2) {
							boiOrder_html = "已取消";
						} else if (data.boiOrder == 3) {
							boiOrder_html = "已结单";
						} else if (data.boiOrder == 4) {
							boiOrder_html = "已失效";
						}

						if (data.boiPay == 0) {
							boiPay_html = "未付款";
						} else if (data.boiPay == 1) {
							boiPay_html = "已付款";
						} else if (data.boiPay == 2) {
							boiPay_html = "已退款";
						}

						if (data.boiShip == 0) {
							boiShip_html = "未配送";
						} else if (data.boiShip == 1) {
							boiShip_html = "配货中";
						} else if (data.boiShip == 2) {
							boiShip_html = "发货中";
						} else if (data.boiShip == 3) {
							boiShip_html = "已发货";
						} else if (data.boiShip == 4) {
							boiShip_html = "已收货";
						} else if (data.boiShip == 5) {
							boiShip_html = "已退货";
						} else if (data.boiShip == 6) {
							boiShip_html = "无法联系";
						}

						$("#boiOsn").html(data.boiOsn);
						$("#boiOsn").attr(
								"href",
								__contextPath
										+ "/user/orderDetail.xhtml?orderId="
										+ data.boiId);
						$("#boiOrder").html(boiOrder_html);
						$("#boiPay").html(boiPay_html);
						$("#boiShip").html(boiShip_html);
					} else {
						alert(Pmt.err_boiOsn_invalid);
						$("#ECS_ORDER_QUERY").hide();
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}

/**
 * 添加商品至收藏夹
 * 
 * @param {}
 *            goodsId
 */
function collect(goodsId) {
	$.ajax({
				url : __contextPath + "/user/addToCollect.xhtml",
				type : "POST",
				data : {
					goodsId : goodsId
				},
				cache : false,
				dataType : 'text',
				success : function(data) {
					if (data != null) {
						alert(data);
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
}
